﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using ApiConceptsFramework.Contract;
using ApiConceptsFramework.FluentApi;
using NUnit.Framework;

namespace test.ApiConceptsFramework.FluentApi.Scenarios.OtherStudies
{
	[TestFixture, Explicit]
	class MethodPlacement
	{
		private Assembly[] _assemblies;
		private string[] _usings;
		private ApiEvaluator _eval;

		#region Setup
		[SetUp]
		public void SetUp()
		{
			_assemblies = new Assembly[] { this.GetType().Assembly };
			_usings = new string[] {};

			_eval = new ApiEvaluator(_assemblies);
			_eval.IDE = IDE.EclipseOrSimilar;
			_eval.SetUsings(_usings);
			_eval.SetAssemblyRefs(_assemblies);
		}

		[TearDown]
		public void TearDown()
		{
			_eval.EvaluateAndPrintToConsole();
		}
		#endregion


		[Test]
		public void EmailTask_simple()
		{
			//_eval.ClassUsage<MimeMessage>();
			_eval.Instantiation(() => new MimeMessage(null));
			_eval.MethodCall((MimeMessage m) => m.setFrom(null));
			_eval.MethodCall((MimeMessage m) => m.setRecipients(null));
			_eval.MethodCall((MimeMessage m) => m.setSubject(null));
			_eval.MethodCall((MimeMessage m) => m.setText(null));
			_eval.MethodCall((MimeMessage m) => m.send());
		}

		[Test]
		public void EmailTask_complex()
		{
			//_eval.ClassUsage<MimeMessage>();
			//_eval.ClassUsage<Transport>();
			_eval.Instantiation(() => new MimeMessage(null));
			_eval.MethodCall((MimeMessage m) => m.setFrom(null));
			_eval.MethodCall((MimeMessage m) => m.setRecipients(null));
			_eval.MethodCall((MimeMessage m) => m.setSubject(null));
			_eval.MethodCall((MimeMessage m) => m.setText(null));
			_eval.MethodCall((MimeMessage m) => m.send());
			_eval.MethodCall((Transport t) => Transport.send(null));
		}

		//MimeMessage msg = new MimeMessage(session);
		//msg.setFrom("ProgrammingStudy@gmail.com");
		//msg.setRecipients(Message.RecipientType.TO,"ProgrammingStudy@gmail.com");
		//msg.setSubject("Test Subject");
		//msg.setText("Test message body");
		//Transport.send(msg);
		//OR
		//msg.send();
		
		class MimeMessage
		{
			public MimeMessage(string arg)
			{ }

			public void setFrom(string arg)
			{ }
			public void setRecipients(string arg)
			{ }
			public void setSubject(string arg)
			{ }
			public void setText(string arg)
			{ }
			public void send()
			{ }
		}

		class Transport
		{
			public static void send(MimeMessage msg)
			{ }
		}


		[Test]
		public void WebAuthTask_simple()
		{
			//_eval.ClassUsage<WebRequest>();
			//_eval.ClassUsage<Authenticator>();
			_eval.Instantiation(() => new WebRequest());
			_eval.MethodCall((WebRequest w) => w.setUrl(null));
			_eval.Instantiation(() => new Authenticator());
			_eval.MethodCall((Authenticator a) => a.setUsername(null));
			_eval.MethodCall((Authenticator a) => a.setPassword(null));

			_eval.MethodCall((WebRequest w) => w.setDefaultAuthenticator(null));

			_eval.MethodCall((WebRequest w) => w.getPageContents());
		}

		[Test]
		public void WebAuthTask_complex()
		{
			//_eval.ClassUsage<WebRequest>();
			//_eval.ClassUsage<Authenticator>();
			//_eval.ClassUsage<Options>();
			_eval.Instantiation(() => new WebRequest());
			_eval.MethodCall((WebRequest w) => w.setUrl(null));
			_eval.Instantiation(() => new Authenticator());
			_eval.MethodCall((Authenticator a) => a.setUsername(null));
			_eval.MethodCall((Authenticator a) => a.setPassword(null));

			_eval.MethodCall((Options o) => Options.setDefaultAuthenticator(null));

			_eval.MethodCall((WebRequest w) => w.getPageContents());
		}

		//WebRequest webRequest = new WebRequest();
		//webRequest.setUrl("http://www.jsstylos.com/protected/test.html");
		//Authenticator authenticator = new Authenticator();
		//authenticator.setUsername("username1");
		//authenticator.setPassword("password1");

		//Options.setDefaultAuthenticator(authenticator);
		//OR
		//webRequest.setDefaultAuthenticator(authenticator);

		//System.out.println(webRequest.getPageContents());

		class WebRequest
		{
			public void setUrl(string arg)
			{ }
			public void setDefaultAuthenticator(Authenticator arg)
			{ }
			public string getPageContents()
			{
				return null;
			}
		}

		class Authenticator
		{
			public void setUsername(string arg)
			{ }
			public void setPassword(string arg)
			{ }
		}

		class Options
		{
			public static void setDefaultAuthenticator(Authenticator arg)
			{ }
		}

	}
}
